home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d8 / tlxtmset.arc / TIMESET.SLT < prev   
Encoding:
Text File  |  1990-12-12  |  6.4 KB  |  284 lines

  1. //    Modified:    12 Dec 1990 - John Grothman
  2. //                Now works with 4DOS, as well as PC-DOS and MS-DOS.
  3. //                (look around line 213 for the change)
  4.  
  5. main()
  6. {
  7.     int    count, hi_hour, lo_hour, hi_min, lo_min, hi_sec, lo_sec, local_hr, t;
  8.     int    error, err_test, y1, y2, y3, y4, y5, day, month, year;
  9.     int    julian1, julian2, julian3, julian4, julian5, julian6, julian7, julian8;
  10.     str    utc_hour[3], slocal_hr[3];
  11.     str    set_dos_time[20]="time ", set_dos_date[20]="date ";
  12.     str    juldatestr[10] = " ";
  13.     str    geordatestr[10] = " ";
  14.     str monthstr[3], daystr[3], yearstr[4];
  15.     int integerdate;
  16.  
  17.     // Initialize variables
  18.     error = 1;            //Indicates that time info is yet to be decoded properly
  19.     err_test = -1;        //Used to detect if time info is properly received
  20.     hi_hour = -1;         //Receives hi byte of hour time info
  21.     lo_hour = -1;         //Receives lo byte of hour time info
  22.     hi_min = -1;        //Receives hi byte of minute time info
  23.     lo_min = -1;        //Receives lo byte of minute time info
  24.     hi_sec = -1;        //Receives hi byte of second time info
  25.     lo_sec = -1;        //Receives lo byte of second time info
  26.     julian1 = -1;
  27.     julian2 = -1;
  28.     julian3 = -1;
  29.     julian4 = -1;
  30.     julian5 = -1;
  31.     _alarm_on = 0;
  32.     _sound_on = 0;
  33.  
  34.     //Show opening TIMESET display
  35.     clear_scr();
  36.     prints("");
  37.     prints("Welcome to Timeset!!!");
  38.     prints("Now dialing The Naval Observertory for the time...");
  39.  
  40.     //Dial for the time
  41.     set_cparams(1200,0,8,1);
  42.     if (!dial("m9-1-202-653-0351",10))
  43.     {
  44.         prints("Can not contact the Naval Observatory! Giving up!");
  45.         tone(300,1);
  46.         return;        //After 10 tries can't reach the time.  Abort.
  47.     }
  48.  
  49.     // Decode the modified Julian time info received
  50.     while (error)
  51.     {
  52.  
  53.         if (!waitfor("UTC",10))
  54.         {
  55.             prints("Timeout error, aborting!");
  56.             hangup();
  57.             _alarm_on = 0;
  58.             _sound_on = 0;
  59.             return;     //Time info is not flowing right.  Abort.
  60.         }
  61.  
  62.         if (!waitfor("*",3))
  63.         {
  64.             prints("Timeout error, aborting!");
  65.             hangup();
  66.             _alarm_on = 0;
  67.             _sound_on = 0;
  68.             return;     //Time info is not flowing right.  Abort.
  69.         }
  70.         flushbuf();
  71.  
  72.         count = 2;       //Amount of bytes to wait until date data should start
  73.         while (count)
  74.         {
  75.             while (cgetc() == -1)
  76.             {
  77.             }
  78.             count = count - 1;
  79.         }
  80.         while (julian1 == -1)
  81.         {
  82.             julian1 = cgetc();
  83.         }
  84.         while (julian2 == -1)
  85.         {
  86.             julian2 = cgetc();
  87.         }
  88.         while (julian3 == -1)
  89.         {
  90.             julian3=cgetc();
  91.         }
  92.         while (julian4 == -1)
  93.         {
  94.             julian4 = cgetc();
  95.         }
  96.         while (julian5 == -1)
  97.         {
  98.             julian5 = cgetc();
  99.         }
  100.  
  101.         count = 5;       //Amount of bytes to wait until time data should start
  102.         while (count)
  103.         {
  104.             while (cgetc() == -1)
  105.             {
  106.             }
  107.             count = count - 1;
  108.         }
  109.  
  110.         //Receive the time data
  111.         while (hi_hour == -1)
  112.         {
  113.             hi_hour = cgetc();
  114.         }
  115.         while (lo_hour == -1)
  116.         {
  117.             lo_hour = cgetc();
  118.         }
  119.         while (hi_min == -1)
  120.         {
  121.             hi_min = cgetc();
  122.         }
  123.         while (lo_min == -1)
  124.         {
  125.             lo_min = cgetc();
  126.         }
  127.         while (hi_sec == -1)
  128.         {
  129.             hi_sec = cgetc();
  130.         }
  131.         while (lo_sec == -1)
  132.         {
  133.             lo_sec = cgetc();
  134.         }
  135.         if (waitfor("UTC",2))
  136.         {
  137.          error = 0;
  138.         }
  139.     }
  140.  
  141.     //Start building the DOS set time command
  142.     strcat(utc_hour, hi_hour);
  143.     strcat(utc_hour, lo_hour);
  144.     local_hr = stoi(utc_hour);
  145.  
  146.     // ****************** Adjust UTC time to local time here *****************
  147.     //Pacific Daylight time is -7 hours
  148.     //Pacific Standard time is -8 hours
  149.     //Central Standard time is -6 hours
  150.  
  151.     local_hr = local_hr - 6;
  152.  
  153.     // ***********************************************************************
  154.     // ***********************************************************************
  155.  
  156.     if (local_hr < 0)
  157.     {
  158.         local_hr = local_hr + 24;
  159.     }
  160.     itos(local_hr, slocal_hr);
  161.  
  162.     //Set DOS time
  163.     strcat(set_dos_time, slocal_hr);
  164.     strcat(set_dos_time, ":");
  165.     strcat(set_dos_time, hi_min);
  166.     strcat(set_dos_time, lo_min);
  167.     strcat(set_dos_time, ":");
  168.     strcat(set_dos_time, hi_sec);
  169.     strcat(set_dos_time, lo_sec);
  170.     dos(set_dos_time, 0);
  171.  
  172.     clear_scr();
  173.     prints("");
  174.     prints("");
  175.     prints("");
  176.     prints("");
  177.     prints("");
  178.     prints("");
  179.     gotoxy(28, gety());
  180.     prints("SUCCESSFULLY set time");
  181.     //Hangup the modem and clear extra received data
  182.     hangup();
  183.     flushbuf();
  184.  
  185.     //Set DOS date
  186.     strcat(juldatestr, "24");        // Add epoch
  187.     strcat(juldatestr, julian1);
  188.     strcat(juldatestr, julian2);
  189.     strcat(juldatestr, julian3);
  190.     strcat(juldatestr, julian4);
  191.     strcat(juldatestr, julian5);
  192.  
  193. //    ** julian to calender date algorithm  **
  194.  
  195. //    The algorithm was obtained directly from the Naval Observatory
  196. //    and should be valid for the next 140 years.
  197. //    If you use it elsewhere, be careful of the integer roundoff.
  198. //    The precedences are critical, therefore the () are inserted
  199. //    to clarify them and prevent mistranslation by the reader.
  200.  
  201.     integerdate = stoi(juldatestr);
  202.     y1 = integerdate + 68569;
  203.     y2 = (4 * y1) / 146097;
  204.     y3 = y1 - (((146097 * y2) + 3) / 4);
  205.     year = (4000 * (y3 + 1)) / 1461001;
  206.     y4 = (y3 - ((1461 * year) / 4)) + 31;
  207.     month = (80 * y4) / 2447;
  208.     day = y4 - ((2447 * month) / 80);
  209.     day = day + 1;
  210.     y5 = month / 11;
  211.     month = month + 2 - (12 * y5);
  212. //    year = 100 * (y2 - 49) + year + y5;
  213.     year = (100 * (y2 - 49) + year + y5) - 1900;
  214.  
  215.  
  216.     itos(integerdate, geordatestr);
  217.     itos(month, monthstr);
  218.     itos(day, daystr);
  219.     itos(year, yearstr);
  220.  
  221.     //Set DOS date
  222.     strcat(set_dos_date, monthstr);
  223.     strcat(set_dos_date, "-");
  224.     strcat(set_dos_date, daystr);
  225.     strcat(set_dos_date, "-");
  226.     strcat(set_dos_date, yearstr);
  227.     dos(set_dos_date, 0);
  228.  
  229.  
  230.     //Display current time continuosly
  231.     _scr_chk_key = 0;      //Disable keyboard scan so inkey will work properly
  232.     cursor_onoff(0);     //Disable the cursor because it is annoying
  233.     clear_scr();
  234.     prints("");
  235.     prints("");
  236.     prints("");
  237.     printsc("julian date = ");
  238.     prints(juldatestr);
  239.     prints("");
  240.     prints("");
  241.     printsc("month = ");
  242.     prints(monthstr);
  243.     printsc("day = ");
  244.     prints(daystr);
  245.     printsc("year = ");
  246.     prints(yearstr);
  247.     prints("");
  248.     prints("");
  249.     prints("");
  250.     prints("Press esc to exit");
  251.     prints("");
  252.     printsc("The time received from the Naval Observatory is        , adjusted to local time.");
  253.  
  254.     while (1)
  255.     {
  256.         gotoxy(48, gety());
  257.         t = curtime();
  258.         if (thour(t) < 10)
  259.         {
  260.             printsc("0");
  261.         }
  262.         printn(thour(t));
  263.         if (tmin(t) < 10)
  264.         {
  265.             printsc("0");
  266.         }
  267.         printn(tmin(t));
  268.         printsc(".");
  269.         if (tsec(t) < 10)
  270.         {
  271.             printsc("0");
  272.         }
  273.         printn(tsec(t));
  274.         if (inkey() == 27)
  275.         {
  276.             break;        //Exit if the esc key is pressed
  277.         }
  278.     }
  279.  
  280.     clear_scr();
  281.     prints("Thank you for using TIMESET!");
  282.     exittelix(0, 1);
  283. }
  284.